﻿using Entities;
using Service.Interface;
using System;
using System.ServiceModel;

namespace Client
{
    class Program
    {
        static void Main(string[] args)
        {
            using (ChannelFactory<IPeopleOperator> channelFactory = new ChannelFactory<IPeopleOperator>(new WSHttpBinding(), 
                "http://localhost:9999/PeopleService"))
            {
                IPeopleOperator proxy = channelFactory.CreateChannel();

                Person person = null;
                try
                {
                    proxy.DeletePerson(person);
                }

                //
                // Application Exception. 
                //
                catch (FaultException<ErrorInformation> fe)
                {
                    Console.WriteLine(fe.Detail.Messages + " in method " + fe.Detail.MethodName + " of service " + fe.Detail.ServiceName);
                }
                catch(FaultException)
                {
                    Console.WriteLine("Application FaultException");
                }

                //
                // Infrastructure Exception. 
                //
                catch (CommunicationException ex)
                {
                    Console.WriteLine("Communication error:" + ex.Message);
                }
                catch(ObjectDisposedException ex)
                {
                    Console.WriteLine("The proxy is closed:" + ex.Message);
                }
                catch (InvalidOperationException ex)
                {
                    Console.WriteLine("InvalidOperation:" + ex.Message);
                }
                catch(TimeoutException ex)
                {
                    Console.WriteLine("Timeout:" + ex.Message);
                }
                catch(Exception)
                {
                    Console.WriteLine("Unknow Infrastructure Exception ");
                }
                Console.Read();
            }
        }
    }
}
